package com.es.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.es.api.enums.BusinessTypeEnum;
import com.es.api.SystemResult;
import com.es.system.domain.SysOperateLog;
import com.es.system.entity.SysOperateLogDO;
import com.es.system.mapper.SysOperateLogMapper;
import com.es.system.service.SysOperateLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户操作日志 服务实现类
 * </p>
 *
 * @author everysucceed
 * @since 2021-12-06
 */
@Transactional
@Service
public class SysOperateLogServiceImpl extends ServiceImpl<SysOperateLogMapper, SysOperateLogDO> implements SysOperateLogService {

    @Override
    public SystemResult<SysOperateLog> listOperatorLogs() {

        return null;
    }

    @Override
    public SystemResult<SysOperateLog> pages(Integer currentPage, Integer pageSize) {
        Page<SysOperateLogDO> page = new Page<>(currentPage, pageSize);
        page = baseMapper.selectPage(page, null);
        SystemResult<SysOperateLog> result = new SystemResult<SysOperateLog>();
        List<SysOperateLog> data = new ArrayList<>();
        System.out.println(page.getRecords());
        page.getRecords().forEach(e -> {
            SysOperateLog v = new SysOperateLog();
            BeanUtils.copyProperties(e, v);
            v.setBusinessType(BusinessTypeEnum.BUSINESS.getTitleByCode(e.getBusinessType()));
            data.add(v);
        });
        SystemResult sr = SystemResult.success(data);
        sr.setCount(page.getTotal());
        return sr;
    }

}
